#ifndef NETWORK_MANAGER_HH
#define NETWORK_MANAGER_HH

#include <list>
#include <boost/asio.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>

#include "NetworkSession.hh"

class								NetworkManager
{
private:
  int								mPort;
  boost::asio::io_service					mService;
  boost::asio::ip::tcp::endpoint				mEndPoint;
  boost::asio::ip::tcp::acceptor				mAcceptor;
  std::list<boost::shared_ptr<NetworkSession> >			mSessions;
  boost::function<void(NetworkSession &)>			mCallbackAccept;
  boost::function<void(NetworkSession &, void *, size_t)>	mCallbackReceive;

  NetworkManager(void);
  NetworkManager(const NetworkManager &);
  NetworkManager &						operator=(const NetworkManager &);

public:
  NetworkManager(int port);
  ~NetworkManager(void);

  void								setCallbackAccept(const boost::function<void(NetworkSession &)>);
  void								setCallbackReceive(const boost::function<void(NetworkSession &, void *, size_t)>);
  void								waitForSession(void);
  void								handleAccept(const boost::system::error_code &, boost::shared_ptr<NetworkSession>);
  void								run(void);
};

#endif // NETWORK_MANAGER_HH
